package com.ai.controller.made.ai_api;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;


import com.ai.entity.alarm.AlgorithmAlarmBO;
import com.ai.entity.alarm.Plc4AlgorithmVo;
import com.ai.service.made.RecordAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;


@RestController
@RequestMapping("/algorithmAPI/record")
@Slf4j
@Api("算法提交告警接口")
public class RecordAPI {

    @Resource
    RecordAlarmService recordAlarmService;

    /**
     * 算法提交识别警告
     *
     * @return
     */
    @PostMapping("/addAlarm")
    @ApiOperation(value = "算法提交识别警告")
    @EnterPathParamLog
    public CommonResponse addAlarm(@RequestBody List<AlgorithmAlarmBO> algorithmAlarmBO) {
        long l = System.currentTimeMillis();
        CommonResponse CommonResponse = recordAlarmService.addAlarm(algorithmAlarmBO);
        log.info("---add alarm spend time :" + (System.currentTimeMillis() - l));
        return CommonResponse;
    }

    /**
     * 修改plc4的内存值、用于线上对接
     * @param algorithmVo
     * @return
     */
    @PostMapping("/modifyPlcMemory")
    @ApiOperation(value = "")
    @EnterPathParamLog
    public CommonResponse modifyPlcMemory (@RequestBody Plc4AlgorithmVo algorithmVo) {

        log.info("===========================  开始修改plc链路中的内存值  ===========================");
        //运行状态

        return   CommonResponse.ok("修改完毕");

    }
//    @PostMapping("/modifyToPlcMessge")
//    @ApiOperation(value = "模拟发送报文给plc2，plc3")
//    @EnterPathParamLog
//    public CommonResponse modifyToPlcMessage (@RequestBody IdentifySysToL1Message identifySysToL1Message) {
//        byte[] messageToPlcOther;
//        if (identifySysToL1Message.getPlcCode().equals(PlcConstants.PLC_1_CODE)){
//            messageToPlcOther = BootNettyClientChannelCache.createMessageToPlc1(identifySysToL1Message);
//        }else {
//            messageToPlcOther = BootNettyClientChannelCache.createMessageToPlcOther(identifySysToL1Message);
//        }
//        Channel channel = BootNettyClientChannelCache.channelMapCache.get(identifySysToL1Message.getPlcCode()).getChannel();
//        channel.writeAndFlush(Unpooled.copiedBuffer(messageToPlcOther));
//        channel.flush();
//        log.info("向 {} 发送报文： 内容：{}",identifySysToL1Message.getPlcCode(),messageToPlcOther);
//
//        return   CommonResponse.ok("报文发送完毕");
//    }
}
